<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	response.setHeader("X-Frame-Options","SAMEORIGIN");
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<jsp:include page="../../public/public.jsp"/>
<script type="text/javascript" src="<%=basePath%>/them/jquery-easyui-1.4.2/ajaxfileupload.js"></script>
<script type="text/javascript">
	$(function(){
		init();
	})
	function refresh(){
		$('#datagrid').datagrid("reload");
	}
	function init() {
		$('#datagrid').datagrid({
			url : "<%=basePath%>video/query", //获取数据地址
			iconCls : "icon-save", //图标
			pagination : true, //开启分页
			pageSize : 10, //每页显示数目 
			pageList : [ 10, 20, 30, 40, 50 ], //选择每页显示数目(与pageSize对应)
			fit : true, //适应大小
			fitColumns : true, //自动扩大或缩小列的尺寸以适应网格的宽度并且防止水平滚动
			nowrap : false, //是否关闭自动换行(true关闭，false开启)
			border : false, //边框
			remoteSort : false,
			singleSelect : true,
			rownumbers : true,
			/* sortName : "createDate",
			sortOrder : 'desc', */
			onDblClickRow: function(index,row){//双击行事件
				//打开窗口
				update(row);
			},
			toolbar:menu_tb,//加载按钮功能
			columns : [ [ {
				title : "视频标题",
				field : "videoTitle",
				align : 'center',
				width : 80
			}, {
				title : "视频简介",
				field : "videoSummary",
				align : 'center',
				width : 120,
				
			},{
				title : "视频分类",
				field : "videoType",
				align : 'center',
				width : 60,
				formatter : function(value, row, index) {
					if(row.videoType==1){
						return "社会信用体系建设";
					}else if(row.videoType==2){
						return "诚信-中国行动";
					}else{
						return "未分类";
					}
				}
			}/* , {
				title : "播放次数",
				field : "videoClicks",
				align : 'center',
				width : 30,
				
			} */,{
				title : "创建时间",
				field : "createDate",
				align : 'center',
				width : 50,
				sortable : true,
				formatter : function(value, row, index) {
					var unixTimestamp = new Date(value);
					return unixTimestamp.toLocaleDateString();
				}
			},{
				title : "修改时间",
				field : "changeDate",
				align : 'center',
				width : 50,
				sortable : true,
				formatter : function(value, row, index) {
					var unixTimestamp = new Date(value);
					return unixTimestamp.toLocaleDateString();
				}
			},{
				title : "显示/隐藏",
				field : "videoStatus",
				align : 'center',
				width : 50,
				sortable : true,
				formatter : function(value, row, index) {
					
					if(value==1){
						
						return '<span><a href="#" style="text-decoration:none;color:green" onclick=del('+row.videoId+','+value+',"'+row.videoTitle+'"'+'); >已 显 示</a></span>';
					}else if(value==2){
						
						return '<span><a href="#" style="text-decoration:none;color:red" onclick=del('+row.videoId+','+value+',"'+row.videoTitle+'"'+'); >已 隐 藏</a></span>';
					}else{
						return "";
					}
				}
			}] ]
		});
	}
	//选中行触发
	function row_selected(){
		var row = $('#datagrid').datagrid('getSelected');
		if (row==null){
			$.messager.alert("友情提示","[请选择要修改的视频!]","error");
		}else{
			update(row);
		}
	}
	//打开添加用户窗口
	function showWindow(){
		
		//打开窗口
		$('#addForm').form('clear');
		//先对表单进行清空
		$("#file_img").val("");
		$("#videoTitle").textbox('setValue',null);
		$("#videoSummary").textbox('setValue',null);
		$("#videoImg").val('');
		$("#show_img").attr("src","<%=basePath %>images/sys/noimage.jpg");
		$("#videoUrl").val('');
		$("#videoType").val(0);
	    $("#td_video").html("");
		$('#add').show();
		$('#add').dialog({
			title: '新增视频',
			width: 630,
			height: 460,
			closed: false,
			cache: false,
			modal: true,
			buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					
				  	if($("#addForm").form('validate')){
				  		var istrue = yz();
						if(istrue == false){
							return;
						}
					  	$.ajax({  
							url:'<%=basePath %>video/addVideo',
							type:'post',
							data:$("#addForm").serialize(),
							dataType:'json',
							error:function(){
								$.messager.alert("友情提示","系统异常,请稍后尝试","error");
							}, 
							success:function(r){ 
								if(r=='1'){
									$.messager.alert("友情提示","[视频添加成功!]","info");
									$('#add').dialog('close');
									$('#datagrid').datagrid("reload");
								}else {
									$.messager.alert("友情提示","[sorry,视频添加失败!]","info");
								}
							}  
						});
				  	}
				    
				}
					
			},{
				text:'退出',
				iconCls:'icon-no',
				handler:function(){
					$('#add').dialog('close');
				}
			}]
		});
}
	function update(row){
		//赋值
		$("#file_img").val("");
		$("#videoTitle").textbox('setValue',row.videoTitle);
		$("#videoSummary").textbox('setValue',row.videoSummary);
		$("#videoImg").val(row.videoImg);
		$("#videoType").val(row.videoType);
		$("#show_img").attr("src","<%=basePath%>them/video/"+row.videoImg);
		
		$("#videoUrl").val(row.videoUrl);
		 var str = 	'<object type="application/x-shockwave-flash" data="<%=basePath %>them/vcastr/vcastr3.swf" width="320" height="220" id="vcastr3">'+
			'	<param name="movie" value="<%=basePath %>them/vcastr/vcastr3.swf"/> '+
			'	<param name="allowFullScreen" value="true" />'+
			'	<param id="fk" name="FlashVars" value="xml=<vcastr>'+
			'									<channel>'+
			'										<item>'+
			'											<source><%=basePath %>them/video/'+row.videoUrl+'</source>'+
			'											<duration>lixian</duration>'+
			'											<title>lixian</title>'+
			'										</item>'+
			'									</channel>'+
			'									<config>'+
			'								              <isAutoPlay>false</isAutoPlay>'+
			'								              <isLoadBegin>true</isLoadBegin>'+
			'									</config>'+
			'									<plugIns>'+
			'										<logoPlugIn>'+
			'											<url><%=basePath %>them/vcastr/logoPlugIn.swf</url>'+
			'											<logoText>信用</logoText>'+
			'											<logoTextAlpha>0.75</logoTextAlpha>'+
			'											<logoTextFontSize>30</logoTextFontSize>'+
			'											<logoTextLink>http://www.ruochigroup.com</logoTextLink>'+
			'											<logoTextColor>0xffffff</logoTextColor>'+
			'											<textMargin>20 20 auto auto</textMargin>'+
			'										</logoPlugIn>'+
			'									</plugIns>'+
			'								</vcastr>"/>'+
			'</object>';
	    $("#td_video").html(str);
		//打开窗口
		$('#add').show();
		$('#add').dialog({
			title: '修改视频',
			width: 630,
			height: 460,
			closed: false,
			cache: false,
			modal: true,
			buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					var istrue = yz();
					if(istrue == false){
						return;
					}
					var videoTitle = $("#videoTitle").textbox('getValue');
					var videoSummary = $("#videoSummary").textbox('getValue');
					var videoImg = $("#videoImg").val();
					var videoUrl = $("#videoUrl").val();
					var videoType=$("#videoType").val();
					  	$.ajax({  
							url:'<%=basePath %>video/updateVideo',
							type:'post',
							data:{
								'videoTitle':videoTitle,
								'videoSummary':videoSummary,
								'videoImg':videoImg,
								'videoUrl':videoUrl,
								'videoId':row.videoId,
								'videoClicks':row.videoClicks,
								'videoType':videoType
							},
							dataType:'json',
							error:function(){
								$.messager.alert("友情提示","系统异常,请稍后尝试","error");
							}, 
							success:function(r){ 
								if(r=='1'){
									$.messager.alert("友情提示","[视频修改成功!]","info");
									$('#add').dialog('close');
									$('#datagrid').datagrid("reload");
								}else {
									$.messager.alert("友情提示","[sorry,视频修改失败!]","info");
								}
							}  
						});
				  	}
			},{
				text:'退出',
				iconCls:'icon-no',
				handler:function(){
					$('#add').dialog('close');
				}
			}]
		});
	}
	//删除/显示/隐藏/视频
	function del(id,value,videoTitle){
		
		var videoId="";
		var videoStatus="";
		var row = $('#datagrid').datagrid('getSelected');
		var strStats = "";
		if(value==0){
			strStats="删除";
			if(row==null){
				$.messager.alert("友情提示","[请选择要"+strStats+"的视频]","info");
				return;
			}
			videoStatus=0
			videoTitle  = row.videoTitle;
			videoId = row.videoId;
			
		}
		if(value==1){
			videoStatus=2;
			videoId = id;
			strStats="隐藏";
		}
		if(value==2){
			videoStatus=1;
			videoId = id;
			strStats="显示";
		}
		if (row==null && videoStatus==0){
			$.messager.alert("友情提示","[请选择要"+strStats+"的视频]","info");
		}else{
			$.messager.confirm('系统提示', '[您确定要'+strStats+'视频:'+videoTitle+"吗?]", function(r) {
				if(r){
					$.ajax({  
						url:'<%=basePath %>video/delVideo',
						type:'post',
						data:{
							'videoId':videoId,
							'videoStatus':videoStatus
						},
						dataType:'json',
						error:function(){
							$.messager.alert("友情提示","正在维护,请稍后尝试","error");
						}, 
						success:function(r){ 
							if(r=='1'){
								$.messager.alert("友情提示","["+strStats+"成功!]","info");
								$('#datagrid').datagrid("reload");
							}else {
								$.messager.alert("友情提示","[sorry,"+strStats+"失败!]","info");
							}
						}  
					}); 
				}
			})
		}
	}
	
	function fn_img_upload(){
	  	  var url = '<%=basePath%>upload/fileUpload';
		  var suffixStr = "jpg,JPG,png,PNG,gif,GIF,bmp,BMP";
		  var savePath = ",them,video";
		  $.ajaxFileUpload
	      ({//String fileObjectId,int MaxSize,String suffixStr,String savePath,int width,int height
	             url: url+'?fileObjectId=file_img&MaxSize='+0+'&suffixStr='+suffixStr+'&savePath='+savePath+'&width='+0+'&height='+0, //用于文件上传的服务器端请求地址
	             secureuri: false, //是否需要安全协议，一般设置为false
	             fileElementId: 'file_img', //文件上传域的ID
	             dataType: 'json', //返回值类型 一般设置为json
	             success: function (data, status)  //服务器成功响应处理函数
	             {
	                 if(data.success=="true"){
	               	     $("#show_img").attr("src","<%=basePath%>them/video/"+data.imgurl);
	               	     $("#videoImg").val(data.imgurl);
	                 }else{
	               	    alert(data.msg);
	                 }
	             },
	             error: function (data, status, e)//服务器响应失败处理函数
	             {
	                 alert(e);
	             }
	      })
  }
  function fn_video_upload(){
	  	  var url = '<%=basePath%>upload/fileUpload';
		  var suffixStr = "flv,FLV";
		  var savePath = ",them,video";
		  $.messager.progress({ 
			    title: 'Please waiting', 
			    msg: 'upload data...', 
			    text: 'PROCESSING.......' 
		  });
		  $.ajaxFileUpload
	      ({//String fileObjectId,int MaxSize,String suffixStr,String savePath,int width,int height
	             url: url+'?fileObjectId=file_video&MaxSize='+0+'&suffixStr='+suffixStr+'&savePath='+savePath+'&width='+0+'&height='+0, //用于文件上传的服务器端请求地址
	             secureuri: false, //是否需要安全协议，一般设置为false
	             fileElementId: 'file_video', //文件上传域的ID
	             dataType: 'json', //返回值类型 一般设置为json
	             success: function (data, status)  //服务器成功响应处理函数
	             {
	                 if(data.success=="true"){
	               	     $("#videoUrl").val(data.imgurl);
	            		 var str = 	'<object type="application/x-shockwave-flash" data="<%=basePath %>them/vcastr/vcastr3.swf" width="320" height="220" id="vcastr3">'+
	 					'	<param name="movie" value="<%=basePath %>them/vcastr/vcastr3.swf"/> '+
	 					'	<param name="allowFullScreen" value="true" />'+
	 					'	<param id="fk" name="FlashVars" value="xml=<vcastr>'+
	 					'									<channel>'+
	 					'										<item>'+
	 					'											<source><%=basePath %>them/video/'+data.imgurl+'</source>'+
	 					'											<duration>lixian</duration>'+
	 					'											<title>lixian</title>'+
	 					'										</item>'+
	 					'									</channel>'+
	 					'									<config>'+
	 					'								              <isAutoPlay>false</isAutoPlay>'+
	 					'								              <isLoadBegin>true</isLoadBegin>'+
	 					'									</config>'+
	 					'									<plugIns>'+
	 					'										<logoPlugIn>'+
	 					'											<url><%=basePath %>them/vcastr/logoPlugIn.swf</url>'+
	 					'											<logoText>信用</logoText>'+
	 					'											<logoTextAlpha>0.75</logoTextAlpha>'+
	 					'											<logoTextFontSize>30</logoTextFontSize>'+
	 					'											<logoTextLink>http://www.ruochigroup.com</logoTextLink>'+
	 					'											<logoTextColor>0xffffff</logoTextColor>'+
	 					'											<textMargin>20 20 auto auto</textMargin>'+
	 					'										</logoPlugIn>'+
	 					'									</plugIns>'+
	 					'								</vcastr>"/>'+
	 					'</object>';
	 					$("#td_video").html(str);
	 					$.messager.progress('close');
	                 }else{
	               	    alert(data.msg);
	               	 	$.messager.progress('close');
	                 }
	             },
	             error: function (data, status, e)//服务器响应失败处理函数
	             {
	                 alert(e);
	                 $.messager.progress('close');
	             }
	      })
  }
  function  yz(){
	    var videoTitle = $("#videoTitle").textbox('getValue').replace(/\s/g, "");
		var videoSummary = $("#videoSummary").textbox('getValue').replace(/\s/g, "");
		var videoImg = $("#videoImg").val().replace(/\s/g, "");
		var videoUrl = $("#videoUrl").val().replace(/\s/g, "");
		var videoType=$("#videoType").val().replace(/\s/g, "");
		if(videoTitle==""){
			$.messager.alert("友情提示","视频标题不允许为空","error");
			return false;
		}
		if(videoSummary==""){
			$.messager.alert("友情提示","视频摘要不允许为空","error");
			return false;
		}
		if(videoType=="0"){
			$.messager.alert("友情提示","视频分类不允许为空","error");
			return false;
		}
		if(videoImg==""){
			$.messager.alert("友情提示","图片地址不允许为空","error");
			return false;
		}
		if(videoUrl==""){
			$.messager.alert("友情提示","视频上传不允许为空","error");
			return false;
		}
		return true;
  }
</script>
</head>
<body class="easyui-layout">
	<div style="height: 100%; width: 100%">
		<!--添加窗口表单-->
		<div id="add" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-edit'" style="padding: 10px;">
			<form id="addForm" method="post">
				<table align="center" style="margin-top: 10px">
					<tr style="height: 30px">
						<td>视频标题：</td>
						<td><input name="videoTitle" id="videoTitle" class="easyui-textbox" data-options="width:350,required:true" /></td>
					</tr>
					<tr style="height: 30px">
						<td>视频摘要：</td>
						<td><input name="videoSummary" id="videoSummary" class="easyui-textbox" data-options="multiline:true,height:60,width:350,required:true" /></td>
					</tr>
					<tr style="height: 30px">
						<td>视频分类：</td>
						<td>
							<select name="videoType" id="videoType">
								<option value="0">请选择</option>
								<option value="1">社会信用体系建设</option>
								<option value="2">诚信-中国行动</option>
								
							</select>
						</td>
					</tr>
					<tr style="height: 30px">
						<td>图片地址：</td>
						<td>
						<input id="file_img" name="file_img" type="file" onchange="fn_img_upload()"/><font color="red">建议:图片宽200*高200</font>
						<input name="videoImg" id="videoImg" type="hidden"/>
						</td>
					</tr>
					<tr>
					    <td></td>
						<td>
							<img id="show_img" src="<%=basePath%>images/sys/noimage.jpg" width="120" height="85">
						</td>
					</tr>
					
					<tr style="height: 30px">
						<td>视频上传：</td>
						<td>
						<input type="file" id="file_video" name="file_video" onchange="fn_video_upload()">
						<font color="red">视频格式必须为.flv</font>
						<input name="videoUrl" id="videoUrl" type="hidden"/>
						</td>
					</tr>
					<tr>
					    <td></td>
						<td id="td_video">
							
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div id="menu_tb">
		     <table>       
		     	<tr>
		            <td>
		                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-mini-refresh" plain="true" onclick="refresh()">刷新列表</a>
		            </td>
		            <td>
		                <div class="datagrid-btn-separator"></div>
		            </td>
		            <td>
		                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-mini-add" plain="true" onclick="showWindow()">新增视频</a>
		            </td>
		            <td>
		                <div class="datagrid-btn-separator"></div>
		            </td>
		            <td>
		            	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-mini-edit" plain="true" onclick="row_selected()">修改视频</a>
		            </td>
		            <td>
		                <div class="datagrid-btn-separator"></div>
		            </td>
		            <td>
		            	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cut" plain="true" onclick="del(0,0,0)">删除视频</a>
		            </td>
		            <td>
		                <div class="datagrid-btn-separator"></div>
		            </td>
		            <td>
		                <div class="datagrid-btn-separator"></div>
		            </td>
		        </tr>
		    </table>
		</div>
	<table id="datagrid"></table>
</div>
</body>

</html>